/**
 * Created by zhangjinrui on 17/6/27.
 */

public class Solution36 {

    public static void main(String args[]){
        Solution36 s = new Solution36();
    }

    public boolean isValidSudoku(char[][] board) {
        int n = 9;
        int mp[][] = new int[10][10];
        int mp2[][] = new int[10][10];
        for(int i = 0 ; i < n; i ++){
            for(int j = 0 ; j < n ; j ++){
                char c = board[i][j];
                if(c == '.'){
                    continue;
                }
                if(c > '9' || c < '1'){
                    return false;
                }
                int v = c - '0';
                mp[i][v] ++;
                if(mp[i][v] > 1){
                    return false;
                }
                mp2[j][v] ++;
                if(mp2[j][v] > 1){
                    return false;
                }
            }
        }
        for(int i = 0 ; i < n ; i += 3){
            for(int j = 0 ; j < n ; j += 3){
                if(!checkF(board, i, j)){
                    return false;
                }
            }
        }
        return true;
    }

    public boolean checkF(char[][] board, int x, int y){
        int[] mp = new int[10];
        for(int i = x; i < x + 3; i ++){
            for(int j = y; j < y + 3; j ++){
                char c = board[i][j];
                if(c == '.'){
                    continue;
                }
                mp[c - '0'] ++;
                if(mp[c - '0'] > 1){
                    return false;
                }
            }
        }
        return true;
    }




}
